import { body } from 'express-validator';

export const code = body('code')
  .exists()
  .withMessage('code is required')
  .bail({ level: 'request' })
  .notEmpty()
  .bail({ level: 'request' })
  .trim()
  .isLength({ max: 50 })
  .withMessage('code length limit 50')
  .bail({ level: 'request' });

export const name = body('name')
  .exists()
  .withMessage('name is required')
  .bail({ level: 'request' })
  .notEmpty()
  .bail({ level: 'request' })
  .trim()
  .isLength({ max: 200 })
  .withMessage('code length limit 200')
  .bail({ level: 'request' });

export const begin_date = body('begin_date')
  .exists()
  .withMessage('begin_date is required')
  .bail({ level: 'request' })
  .notEmpty()
  .bail({ level: 'request' })
  .trim()
  .isDate({ format: 'YYYY-MM-DD', delimiters: ['-'] })
  .bail({ level: 'request' });

export const end_date = body('end_date')
  .exists()
  .withMessage('end_date is required')
  .bail({ level: 'request' })
  .notEmpty()
  .bail({ level: 'request' })
  .trim()
  .isDate({ format: 'YYYY-MM-DD', delimiters: ['-'] })
  .bail({ level: 'request' });

export const hotel_id = body('hotel_id')
  .customSanitizer((value, { req }) => req.user.hotel_id);

export const disabled = body('disabled')
  .toBoolean();

export const sequence = body('sequence')
  .toInt(10);

export const version = body('version')
  .isInt({ min: 0 })
  .withMessage('version must greater or equal to 0')
  .bail({ level: 'request' });

export const reference = body('reference')
  .optional({ values: 'falsy' })
  .trim()
  .isLength({ min: undefined, max: 500 })
  .withMessage('reference length limit 500')
  .bail({ level: 'request' });
